package com.me.customerdemo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.me.customerdemo.dao.BaseDictMapper;
import com.me.customerdemo.pojo.BaseDict;
import com.me.customerdemo.pojo.Server;
import com.me.customerdemo.service.BaseDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BaseDictServerImpl implements BaseDictService {

    @Autowired
    private BaseDictMapper baseDictMapper;

    @Override
    public List<BaseDict> selectAll() {
        return baseDictMapper.selectAll();
    }

    @Override
    public boolean updateById(BaseDict baseDict) {
        return baseDictMapper.updateById(baseDict)>0? true:false;
    }

    @Override
    public boolean deleteById(int id) {
        return baseDictMapper.deleteById(id)>0?true:false;
    }

    @Override
    public boolean apply(BaseDict baseDict) {
        return baseDictMapper.apply(baseDict)>0?true:false;
    }




//    @Override
//    public PageInfo<BaseDict> findAll(int pageNum, int pageSize) {
//        PageHelper.startPage(pageNum, pageSize);
//        List<BaseDict> baseDicts=baseDictMapper.selectAll();
//        PageInfo<BaseDict> page=new PageInfo<>(baseDicts);
//        return page;
//    }

    @Override
    public PageInfo<BaseDict> findByKeyword(int pageNum, int pageSize, String keyword) {

        PageHelper.startPage(pageNum,pageSize);
        List<BaseDict> baseDicts=baseDictMapper.selectByKeyWord(keyword);
        PageInfo<BaseDict> page= new PageInfo<>(baseDicts);
        return page;
    }

    @Override
    public BaseDict findById(int id) {
        return baseDictMapper.selectById(id);
    }


    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean modify(BaseDict baseDict) {
        return baseDictMapper.updateById(baseDict) > 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean removeById(int id) {
        return baseDictMapper.deleteById(id) > 0;
    }
}
